import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const router = new VueRouter({
    routes:[
            {path:'/',redirect: {name:'login'}},
            { 
                name:'login',
                path: '/login',
                component:()=>import('../components/day06/login/login.vue') 
            },
            { 
                name:'index', 
                path: '/index', 
                component:()=>import('../components/day06/login/index.vue') 
            },
    ]
})

router.beforeEach((to, from, next) => {
    console.log(to);
   if(to.path=='/login'){
        next()
   }else{
       let token=localStorage.getItem('taken')
       console.log(token);
       if(token){
           
           next()
       }else{
           next({path:'/login'})
       }
   }
  })
  export default router